unit Con_RegrasPagto;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids,
  Db, Dbtables, TFlatButtonUnit;

type
  TFrmCon_RegrasPagto = class(TFrmConsulta)
    Label1: TLabel;
    EdtDescricao: TEdit;
    DbgRegrasPagto: TDBGrid;
    bcadastrar: TFlatButton;
    procedure BtnFecharClick(Sender: TObject);
    procedure EdtDescricaoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure bcadastrarClick(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    Reg_codigo: string;
    xmostra_botao: boolean;
  end;

var
  FrmCon_RegrasPagto: TFrmCon_RegrasPagto;

implementation

uses Dm, Biblio, clsRegrasPagto, Cad_RegrasPagto;

{$R *.DFM}

var
  RegrasPagto: TRegrasPagto;
  tds: Tdatasource;
  tq: Tquery;

procedure TFrmCon_RegrasPagto.BtnFecharClick(Sender: TObject);
begin
  inherited;
  Reg_codigo := tq.fieldbyname('Reg_codigo').asstring;
  tds.free;
  tq.close;
  tq.free;
end;

procedure TFrmCon_RegrasPagto.EdtDescricaoKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key = 12 then begin
    FazConsulta;
    EdtDescricao.setfocus;
  end;
end;

procedure TFrmCon_RegrasPagto.FormActivate(Sender: TObject);
begin
  inherited;
  tds := TDataSource.create(self);
  tq := Tquery.create(self);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tds.DataSet := tq;
  fazconsulta;
  EdtDescricao.setfocus;
  bcadastrar.visible := xmostra_botao;
end;

procedure TFrmCon_RegrasPagto.FazConsulta;
var
  mostra: Boolean;
begin
  mostra := not xmostra_botao;
  RegrasPagto.Consultar(tq, EdtDescricao.text, mostra);
  dbgRegrasPagto.DataSource := tds;
  tq.open;
  dbgRegrasPagto.Refresh;
end;

procedure TFrmCon_RegrasPagto.FormCreate(Sender: TObject);
begin
  inherited;
  RegrasPagto := TRegrasPagto.create;
end;

procedure TFrmCon_RegrasPagto.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  RegrasPagto.Free;
end;

procedure TFrmCon_RegrasPagto.bcadastrarClick(Sender: TObject);
begin
  inherited;
  Executa(TFrmCad_RegrasPagto, self);
  FazConsulta;
end;

end.
